Skip to content

Conversation

@sgindeed
Copy link
Contributor

@sgindeed sgindeed commented Oct 7, 2025

This PR adds a new R script unique.letters.count.R that:

  • Prompts the user to enter a string.
  • Cleans the string by removing non-letter characters and converting it to lowercase.
  • Finds all unique letters in the string.
  • Counts the occurrences of each unique letter.
  • Displays the letters along with their counts.

Variable names use dots (.) instead of underscores to follow the naming style preference.

Example:
Input: "Hello World!"
Output:
h : 1
e : 1
l : 3
o : 2
w : 1
r : 1
d : 1

@sgindeed sgindeed requested review from acylam and siriak as code owners October 7, 2025 06:12
@siriak siriak requested a review from Copilot October 7, 2025 21:51
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds a new R program for counting unique letters in a string and refactors an existing cocktail sort implementation to follow consistent naming conventions. The changes standardize the codebase to use dot notation for variable and function names throughout.

  • Adds a new interactive string manipulation program that counts unique letter occurrences
  • Refactors the cocktail sort algorithm to use consistent dot notation naming
  • Simplifies code structure and removes redundant comments in the sorting algorithm

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
string_manipulation/unique.letters.count.R New R script that prompts for user input and counts unique letters in cleaned strings
sorting_algorithms/cocktail_sort.r Refactored to use dot notation naming and simplified code structure

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

input.string <- readline(prompt = "Enter a string: ")

# Convert to lowercase and remove non-letter characters
clean.string <- tolower(gsub("[^a-z]", "", input.string))
Copy link

Copilot AI Oct 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The regex pattern [^a-z] will remove uppercase letters before tolower() is applied. This should be [^a-zA-Z] to preserve all letters before converting to lowercase, or the order should be reversed to apply tolower() first.

Suggested change
clean.string <- tolower(gsub("[^a-z]", "", input.string))
clean.string <- tolower(gsub("[^a-zA-Z]", "", input.string))

Copilot uses AI. Check for mistakes.
unique.letters <- unique(letters.vec)

# Count occurrences of each unique letter
letter.counts <- table(letters.vec)
Copy link

Copilot AI Oct 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The table() function is called on letters.vec but only values from unique.letters are accessed. This creates unnecessary computation for letters that won't be displayed. Consider using letter.counts <- table(letters.vec)[unique.letters] or iterating directly over the table results.

Suggested change
letter.counts <- table(letters.vec)
letter.counts <- table(letters.vec)[unique.letters]

Copilot uses AI. Check for mistakes.
# Display results
cat("Unique letters and their counts:\n")
for (letter in unique.letters) {
cat(letter, ":", letter.counts[letter], "\n")
Copy link

Copilot AI Oct 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The table() function is called on letters.vec but only values from unique.letters are accessed. This creates unnecessary computation for letters that won't be displayed. Consider using letter.counts <- table(letters.vec)[unique.letters] or iterating directly over the table results.

Copilot uses AI. Check for mistakes.
@siriak
Copy link
Member

siriak commented Oct 7, 2025

Please check comments

@sgindeed sgindeed closed this Oct 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants